#include <iostream>
using namespace std;
int main(){
    int l, m, c=0;
    cin >> l >> m;
    int arr[10010] = {0};
    for (int i = 0; i < m; i++) {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        for (int j = tmp1; j <= tmp2; j++) {
            arr[j] = 1;
        }
    }
    for (int i = 0; i <= l; i++) {
        if (arr[i] == 0) {
            c++;
        }
    }
    cout << c;
}
